<?php
 $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_rullke");
  if(isSet($_REQUEST["uusleht"])){
 $kask=$yhendus->prepare("INSERT INTO inimesed (eesnimi, perenimi, email, peonimi) VALUES (?, ?, ?, ?)");
 $kask->bind_param("ssss", $_REQUEST["eesnimi"], $_REQUEST["perenimi"], $_REQUEST["email"], $_REQUEST["peonimi"]);
 $kask->execute();
 header("Location: $_SERVER[PHP_SELF]");
 $yhendus->close();
 exit();
 }
 if(isSet($_REQUEST["kustutusid"])){
 $kask=$yhendus->prepare("DELETE FROM inimesed WHERE id=?");
 $kask->bind_param("i", $_REQUEST["kustutusid"]);
 $kask->execute(); 
 }
 if(isSet($_REQUEST["kustutusid"])){
 $kask=$yhendus->prepare("DELETE FROM inimesed WHERE id=?");
 $kask->bind_param("i", $_REQUEST["kustutusid"]);
 $kask->execute(); 
 }
?>
<!doctype html>
<html>
 <head>
 <title>PEOÕHTU ADMINILEHT</title>
 <style type="text/css">
 #menyykiht{
 float: left;
 padding-right: 30px;
 }
 #sisukiht{
 float:left;
 }
 #jalusekiht{
 clear: left;
 }

 </style>
 </head>
 <body>
 <div id="menyykiht">
 <h2>REGATUD INIMESED</h2>
 <a href='?lisamine=jah'>Lisa ...</a>
 <ul>
 <?php
 $kask=$yhendus->prepare("SELECT id, eesnimi, perenimi, email, peonimi FROM inimesed"); 
 $kask->bind_result($id, $eesnimi, $perenimi, $email, $peonimi);
 $kask->execute();
 while($kask->fetch()){
 echo "<table>"."<th>id:</th><tr><td>".htmlspecialchars($id)."</td></tr>";
 echo "<th>EESNIMI:</th><tr><td>".htmlspecialchars($eesnimi)."</td></tr>";
 echo "<th>PERENIMI:</th><tr><td>".htmlspecialchars($perenimi)."</td></tr>";
 echo "<th>EMAIL:</th><tr><td>".htmlspecialchars($email)."</td></tr>";
 echo "<th>PEONIMI:</th><tr><td>".htmlspecialchars($peonimi)."</td></tr>";
 echo "<br /><a href='?kustutusid=$id'>kustuta</a>"."</table>";
 }
 ?>
 </ul>
  </div>
 <div id="sisukiht">
 <?php
 if(isSet($_REQUEST["lisamine"])){
 ?>
 <form action='?'>
 <input type="hidden" name="uusleht" value="jah" />
 <h2>Uue peolise lisamine</h2>
 <dl>
 <dt>Nimi:</dt>
 <dd>
 <input type="text" name="eesnimi" />
 </dd>
 <dt>Perenimi:</dt>
 <dd>
 <input type="text" name="perenimi" />
 </dd>
 <dt>Email:</dt>
 <dd>
 <input type="text" name="email" />
 </dd>
 <dt>Peonimi:</dt>
 <dd>
 <input type="text" name="peonimi" />
 </dd>
 </dl>
 <input type="submit" value="sisesta">
 </form>
 <?php
 }
 ?>
 
 </div>
 <div id="jalusekiht">

 </div>
 </body>
</html>
<?php
 $yhendus->close();
?>